package com.hygj.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hygj.pojo.IntermediaryOffice;
import com.hygj.service.IntermediaryOfficeService;
import com.hygj.util.PageUtil;

@Controller
@RequestMapping
public class IntermediaryOfficeController {
	
	@Autowired
	private IntermediaryOfficeService intermediaryOfficeService;
	
	/**
	 * 保存
	 * 
	 * @param intermediary
	 * @return
	 */
	@RequestMapping(value = "insertIntermediaryOffice", method = RequestMethod.POST)
	public String insertIntermediaryOffice(Map<String, Object> map, IntermediaryOffice intermediaryOffice) {
		intermediaryOfficeService.insert("insert", intermediaryOffice);
		map.put("intermediaryOffice", intermediaryOffice);
		return "redirect:getIntermediaryOfficeAll";
	}
     
	
	/**
	 * 各种修改(禁用|启用。。。。)
	 * @param printOffice
	 * @return
	 */
	@RequestMapping("updateIntermediaryOffice")
	public String updatePrintOffice(IntermediaryOffice intermediaryOffice){
		intermediaryOfficeService.update("update", intermediaryOffice);
		return "redirect:getIntermediaryOfficeAll";
	}
	
	/**
	 * 删除
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping("deleteIntermediaryOffice")
	public String deleteIntermediaryOffice(@RequestParam("id") Integer id) {
		intermediaryOfficeService.delete("delete", id);
		return "redirect:getIntermediaryOfficeAll";
	}
    
	/**
	 * 查询全部
	 * 
	 * @param map
	 * @param request
	 * @return
	 */
	@RequestMapping("getIntermediaryOfficeAll")
	public String getIntermediaryOfficeAll(@ModelAttribute("search") IntermediaryOffice intermediaryOffice, Map<String, Object> map,
			HttpServletRequest request) {
		Map<String, Object> params = new HashMap<String, Object>();
		PageUtil<IntermediaryOffice> page = intermediaryOfficeService.page(request, 10, params);
		map.put("page", page);
		return "intermediarys/intermediaryOfficeShow";
	}

	/**
	 * 详情页面
	 * 
	 * @param id
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("getIntermediaryOfficeById")
	public String getIntermediaryOfficeById(@RequestParam("id") Integer id, ModelMap modelMap) {
		IntermediaryOffice intermediaryOffices = intermediaryOfficeService.getById("getById", id);
		modelMap.addAttribute("intermediaryOffices", intermediaryOffices);
		return "intermediarys/intermediaryOfficeDetails";
	}
	
	
	/**
	 * 修改--详情
	 * 
	 * @param id
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("getIntermediaryOfficeByIdss")
	public String getIntermediaryOfficeByIdss(@RequestParam("id") Integer id, ModelMap modelMap) {
		IntermediaryOffice intermediaryOffices = intermediaryOfficeService.getById("getById", id);
		modelMap.addAttribute("intermediaryOffices", intermediaryOffices);
		return "intermediarys/intermediaryOfficeUpdate";
	}

	/**
	 * 禁用页面查询
	 * 
	 * @param id
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("getIntermediaryOfficeByIds")
	public String getIntermediaryOfficeByIds(@RequestParam("id") Integer id, ModelMap modelMap) {
		IntermediaryOffice intermediaryOffice = intermediaryOfficeService.getById("getById", id);
		modelMap.addAttribute("intermediaryOffice", intermediaryOffice);
		return "intermediarys/intermediaryOfficeOpen";
	}
	
	
	/**
	 * 随机抽取
	 * 
	 * @param response
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping("looks")
	public List<IntermediaryOffice> randomNum(HttpServletResponse response, HttpServletRequest request) {
		List<IntermediaryOffice> intermediaryOffices = intermediaryOfficeService.findRandomByName("启用");
		return intermediaryOffices;
	}

}
